﻿//----------------------------------------------------------------------------------------------------
// Assert handler
//----------------------------------------------------------------------------------------------------
package HG
{
	import flash.system.Capabilities;
	import HG.Visual.DebugConsole;
	
	public class Debug
	{
		static var m_console:DebugConsole;
		
		//----------------------------------------------------------------------------------------------------
		public function Debug()
		{
		}
		
		//----------------------------------------------------------------------------------------------------
		// Check if is debug copy of the game.
		//----------------------------------------------------------------------------------------------------
		public static function IsDebug():Boolean
		{
			return Capabilities.isDebugger;
		}
		
		//----------------------------------------------------------------------------------------------------
		// Trace is used to show messages in the output console
		//----------------------------------------------------------------------------------------------------
		public static function Trace(message:String)
		{
			trace(message);
			
			if (m_console)
				m_console.Output(message);
		}
		
		//----------------------------------------------------------------------------------------------------
		// Assert accepts any type for first paramater, objects default to test !NULL.
		//----------------------------------------------------------------------------------------------------
		public static function ASSERT(test, assertMessage:String):void
		{
			if (!test)
			{
				Debug.Trace(new Error("ASSERT FAILED").getStackTrace() + "\nMessage: " + assertMessage);
			}
		}
		
		//----------------------------------------------------------------------------------------------------
		public static function RegisterConsole(console:DebugConsole)
		{
			m_console = console;
		}
	}
}